<?php

namespace Admin\Controller;

use Admin\Controller\CommonController;

class CountController extends CommonController {
	/**
	 * 安装统计
	 */
    public function install(){
    	$post = $_POST;
    	if(!empty($post['statime']) && $post['endtime']){
    		$map['stadate'] = $post['statime'];
    		$map['enddate'] = $post['endtime'];
    		$this->assign('statime',$map['stadate']);
    		$this->assign('endtime',$map['enddate']);
    	}elseif(!empty($post['time'])){
    		switch($post['time']){
    			case 1:
					//上周
					$map['stadate'] = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+1-7,date("Y")));
					$map['enddate'] = date("Y-m-d",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y")));
    				$this->assign('time',$post['time']);
    				break;
    			case 2:
					//本周
					$map['stadate'] = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+1,date("Y")));
	    			$map['enddate'] = date("Y-m-d",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y")));
    				$this->assign('time',$post['time']);
    				break;
    			case 3:
					//上月
					$map['stadate'] = date("Y-m-d",mktime(0,0,0,date("m")-1,1,date("Y")));
	    			$map['enddate'] = date("Y-m-d",mktime(23,59,59,date("m") ,0,date("Y")));
    				$this->assign('time',$post['time']);
    				break;
    			case 4:
					//本月
					$map['stadate'] = date("Y-m-d",mktime(0,0,0,date("m"),1,date("Y")));
	    			$map['enddate'] = date("Y-m-d",mktime(23,59,59,date("m"),date("t"),date("Y")));
    				$this->assign('time',$post['time']);
    				break;
    		};
    	}
    	$params = array(
    		'map' => $map
    	);
		$data = D('Installcount')->installcount($params);
		$list = json_encode($data);
		$this->assign('list',$list);
		$this->assign('data',$data);
		$this->display();
	}


	/**
	 * 活跃统计
     */
	public function active(){
		$post = $_POST;
		if(!empty($post['statime']) && $post['endtime']){
			$map['stadate'] = $post['statime'];
			$map['enddate'] = $post['endtime'];
			$this->assign('statime',$map['stadate']);
			$this->assign('endtime',$map['enddate']);
		}elseif(!empty($post['time'])){
			switch($post['time']){
				case 1:
					//上周
					$map['stadate'] = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+1-7,date("Y")));
					$map['enddate'] = date("Y-m-d",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y")));
					$this->assign('time',$post['time']);
					break;
				case 2:
					//本周
					$map['stadate'] = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+1,date("Y")));
					$map['enddate'] = date("Y-m-d",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y")));
					$this->assign('time',$post['time']);
					break;
				case 3:
					//上月
					$map['stadate'] = date("Y-m-d",mktime(0,0,0,date("m")-1,1,date("Y")));
					$map['enddate'] = date("Y-m-d",mktime(23,59,59,date("m") ,0,date("Y")));
					$this->assign('time',$post['time']);
					break;
				case 4:
					//本月
					$map['stadate'] = date("Y-m-d",mktime(0,0,0,date("m"),1,date("Y")));
					$map['enddate'] = date("Y-m-d",mktime(23,59,59,date("m"),date("t"),date("Y")));
					$this->assign('time',$post['time']);
					break;
			};
		}
		$params = array(
			'map' => $map
		);
		$data = D('Activecount')->activecount($params);
		$list = json_encode($data);
		$this->assign('list',$list);
		$this->assign('data',$data);
		$this->display();
	}

	
}